package com.hunnyovo.springframework.beans;

import java.util.ArrayList;
import java.util.List;

/**
 * 多值对象
 *
 * @author Create By Cb
 * @date 2022/10/26 18:36
 **/
public class PropertyValues {

    private final List<PropertyValue> propertyValueList = new ArrayList<>();

    /**
     * 添加值对象
     *
     * @param name:
     * @param value:
     * @author Create By Cb
     * @date 2022/11/23 16:08
     */
    public void addPropertyValue(String name, Object value) {
        this.propertyValueList.add(new PropertyValue(name, value));
    }

    /**
     * 返回值对象数组
     *
     * @return {@link PropertyValue[]}
     * @author Create By Cb
     * @date 2022/11/23 16:10
     */
    public PropertyValue[] getPropertyValues() {
        return this.propertyValueList.toArray(new PropertyValue[0]);
    }

    /**
     * 通过name获取值对象
     *
     * @param name:
     * @return {@link PropertyValue}
     * @author Create By Cb
     * @date 2022/11/23 16:11
     */
    public PropertyValue getPropertyValue(String name) {
        return this.propertyValueList
                .stream()
                .filter(data -> data.getName().equals(name))
                .findFirst()
                .orElse(null);
    }

}
